package com.cgbl.cg.adapter

import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import com.cgbl.cg.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.CourseAllTypeBean
import com.robot.base.view.CgTextView

class ClassificationTabAdapter :
    BaseQuickAdapter<CourseAllTypeBean, BaseViewHolder>(R.layout.app_item_classification_tab) {
    var position = 0
    override fun convert(holder: BaseViewHolder, item: CourseAllTypeBean) {
        val tvName = holder.getView<CgTextView>(R.id.item_tv_name)
        tvName.text = item.name
        tvName.isSelected = position == holder.bindingAdapterPosition

        tvName.setOnClickListener {
            position = holder.bindingAdapterPosition
            if(getOnItemClickListener()!=null){
                getOnItemClickListener()?.onItemClick(this, it, holder.bindingAdapterPosition)
            }
            notifyDataSetChanged()
        }
    }
}